package com.ruoyi.project.charging.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.charging.task.ChargingMqttTask;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.charging.domain.TChargingMqttMsg;
import com.ruoyi.project.charging.service.ITChargingMqttMsgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 岸电MQTT消息原始数据Controller
 * 
 * @author Yaoxuan Mo
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/charging/msg")
public class TChargingMqttMsgController extends BaseController
{
    @Autowired
    private ITChargingMqttMsgService tChargingMqttMsgService;
    
    @Autowired
    private ChargingMqttTask chargingMqttTask;

    /**
     * 查询岸电MQTT消息原始数据列表
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(TChargingMqttMsg tChargingMqttMsg)
    {
        startPage();
        List<TChargingMqttMsg> list = tChargingMqttMsgService.selectTChargingMqttMsgList(tChargingMqttMsg);
        return getDataTable(list);
    }

    /**
     * 导出岸电MQTT消息原始数据列表
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:export')")
    @Log(title = "岸电MQTT消息原始数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TChargingMqttMsg tChargingMqttMsg)
    {
        List<TChargingMqttMsg> list = tChargingMqttMsgService.selectTChargingMqttMsgList(tChargingMqttMsg);
        ExcelUtil<TChargingMqttMsg> util = new ExcelUtil<TChargingMqttMsg>(TChargingMqttMsg.class);
        util.exportExcel(response, list, "岸电MQTT消息原始数据数据");
    }

    /**
     * 获取岸电MQTT消息原始数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:query')")
    @GetMapping(value = "/{msgid}")
    public AjaxResult getInfo(@PathVariable("msgid") String msgid)
    {
        return success(tChargingMqttMsgService.selectTChargingMqttMsgByMsgid(msgid));
    }

    /**
     * 新增岸电MQTT消息原始数据
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:add')")
    @Log(title = "岸电MQTT消息原始数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TChargingMqttMsg tChargingMqttMsg)
    {
        return toAjax(tChargingMqttMsgService.insertTChargingMqttMsg(tChargingMqttMsg));
    }

    /**
     * 修改岸电MQTT消息原始数据
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:edit')")
    @Log(title = "岸电MQTT消息原始数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TChargingMqttMsg tChargingMqttMsg)
    {
        return toAjax(tChargingMqttMsgService.updateTChargingMqttMsg(tChargingMqttMsg));
    }

    /**
     * 删除岸电MQTT消息原始数据
     */
    @PreAuthorize("@ss.hasPermi('charging:msg:remove')")
    @Log(title = "岸电MQTT消息原始数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgids}")
    public AjaxResult remove(@PathVariable String[] msgids)
    {
        return toAjax(tChargingMqttMsgService.deleteTChargingMqttMsgByMsgids(msgids));
    }
    
    @GetMapping("/manualConvert")
    public String manualConvert(){
        chargingMqttTask.autoConvertChargingMqttMsg();
        return "success";
    }
}
